package dao.impl;

import dao.AdminuserDao;
import pojo.Adminuser;

import java.sql.SQLException;
import java.util.ArrayList;

public class AdminuserDaoImpl extends BaseDao implements AdminuserDao{

    @Override
    public ArrayList<Adminuser> getAdminuser() {
        Adminuser a=null;
        ArrayList<Adminuser> aduList = new ArrayList<Adminuser>();
        this.getConnection();

        try {
            this.state =this.conn.createStatement();
            this.rs = this.state.executeQuery("SELECT  * from adminuser");
            while (rs.next()){
                a = new Adminuser();
                a.setAduID(rs.getInt("aduID"));
                a.setAduName(rs.getString("aduName"));
                a.setAduPsw(rs.getString("aduPwd"));

                aduList.add(a);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  aduList;
    }

    @Override
    public boolean searchAdmin(String userName, String psd) {
        boolean res = false;
        String strSQL = "SELECT * from adminuser WHERE aduName =? AND aduPwd = ?";
        try {
            this.conn = this.getConnection();
            this.pst = this.conn.prepareStatement(strSQL);
            this.pst.setString(1,userName);
            this.pst.setString(2,psd);
            res = pst.execute();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return res;
    }
}
